// pages/photo/photo.js
const http = require("../../utils/request");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    enable: false,
    loadingProps: {
      size: '40rpx',
    },
    backTopVisible: false,
    index:'1',
    ids:[],
    note:'养殖批次',
    note_val:'CULTIVATION',
    visible:false,
    loaded:false,
    amount:1,
    isnull:false,
    options:[
      {label:"养殖批次",value:"CULTIVATION"},
      {label:"屠宰批次",value:"SLAUGHTER"},
    ],
    photo_cul: {
      title: "标题",
      captureAddress: "地址",
      farmer: "养殖户",
    },
    photo_sla:{
      title: "标题",
      captureAddress: "地址",
      farmer: "屠宰户",
    },
    type_cul:{
      code:"养殖批次",
      createTime:"创建时间",
      type:"CULTIVATION"
    },
    type_kill:{
      code:"屠宰批次",
      createTime:"创建时间",
      type:"SLAUGHTER"
    },
    now_type:{
      code:"养殖批次",
      createTime:"创建时间",
      type:"CULTIVATION"
    },
    now_photo:{
      title: "标题",
      captureAddress: "地址",
      farmer: "养殖户",
    }
  },
  changeindex(e){
    console.log(e);
    this.setData({
      index: e.currentTarget.dataset.data
    })
  },
  onPicker(){
    this.setData({
      visible:true
    })
  },
  onPickerCancel(){
    this.setData({
      visible:false
    })
  },

  load(){
    this.setData({
      loaded:false,
    })
    http.getRequest(
      "/admin/verification/1/" + this.data.amount+"?type="+this.data.note_val,
      {},
      (res) => {
        console.log(res);
        this.setData({
          amount: res.data.data.totalRecord,
        })
        http.getRequest(
          "/admin/verification/1/" + this.data.amount+"?type="+this.data.note_val,
          {},
          (res) => {
            let data = [];
            let isnull = false;
            if(res.data.data&&res.data.data.records.length>0){
              data = res.data.data.records;
            }else{
              isnull = true
            }
            this.setData({
              ids: data,
              isnull: isnull,
            });
            this.setData({
              loaded:true
            })
          },
          (err) => {
          }
        );
      },
      (err) => {
      }
    );
  },
  onPickerChange(e){
    const { value } = e.detail;
    const { label } = e.detail;
    console.log('picker change:',e);
    this.setData({
      visible:false,
      note: label,
      note_val:value,
    })
    if(value=='CULTIVATION'){
      this.setData({
        now_type: this.data.type_cul,
        now_photo:this.data.photo_cul
      })
    }else if(value=='SLAUGHTER'){
      this.setData({
        now_type: this.data.type_kill,
        now_photo: this.data.photo_sla
      })
    }
    this.load();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.load();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.load();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onRefresh() {
    this.setData({ enable: true });
    this.load();
    setTimeout(() => {
      this.setData({ enable: false });
    }, 500);
  },
  onScroll(e) {
    const { scrollTop } = e.detail;
    this.setData({
      backTopVisible: scrollTop > 100,
    });
  },
})